﻿using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace SpellChecker.Tests
{
  [TestFixture]
  class TestCheckWords
  {
    private Dictionary<string, bool> _knownWords;

    [SetUp]
    public void SetUp()
    {
      _knownWords = new Dictionary<string, bool>
                            {
                              {"Hallo", false},
                              {"Stefan", false},
                              {"München", false},
                              {"xyz", false},
                            };
    }

    [Test, ExpectedException(typeof(NullReferenceException))]
    public void TestNullWordsToCheck()
    {
      var inputWordsToCheck = (string[])null;
      var result = SpellChecker.CheckWords(inputWordsToCheck, _knownWords);
      var expected = "";

      Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void TestZeroWords()
    {
      var inputWordsToCheck = new string[0];
      var result = SpellChecker.CheckWords(inputWordsToCheck, _knownWords);
      var expected = true;

      Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void TestOneKnownWord()
    {
      var inputWordsToCheck = new[]{"Hallo"};
      var result = SpellChecker.CheckWords(inputWordsToCheck, _knownWords);
      var expected = true;

      Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void TestOneUnknownWord()
    {
      var inputWordsToCheck = new[] { "Hallo1" };
      var result = SpellChecker.CheckWords(inputWordsToCheck, _knownWords);
      var expected = false;

      Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void TestTwoKownWords()
    {
      var inputWordsToCheck = new[] 
        { 
          "Hallo",
          "Stefan",
        };
      var result = SpellChecker.CheckWords(inputWordsToCheck, _knownWords);
      var expected = true;

      Assert.That(result, Is.EqualTo(expected));
    }

    [Test]
    public void TestTwoUnknownWords()
    {
      var inputWordsToCheck = new[] 
        { 
          "Hallo",
          "Steföan",
        };
      var result = SpellChecker.CheckWords(inputWordsToCheck, _knownWords);

      Assert.That(result, Is.False);
    }

  }
}
